﻿using System;
using System.Configuration;
using System.Data.Linq;
using System.Linq;
using Controllers;

namespace Web
{
    public partial class EvecLogout : System.Web.UI.Page
    {
        protected ReqEvectionMain reqEvectionMain;
        protected string empName;
        protected void Page_Load(object sender, EventArgs e)
        {
            string formNo = Request.QueryString["formNo"];
            ApolloOaDataContext ctx = new ApolloOaDataContext(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
            DataLoadOptions dlo = new DataLoadOptions();
            dlo.LoadWith<ReqEvectionMain>(r => r.ReqEvectionSchedules);
            dlo.LoadWith<ReqEvectionMain>(r => r.ReqEvectionVoyages);
            dlo.LoadWith<ReqEvectionMain>(r => r.ReqEvectionFlighters);
            ctx.LoadOptions = dlo;
            reqEvectionMain = ctx.ReqEvectionMains.Single(r => r.FormNo == formNo);

            Employee employee = ctx.Employees.Single(r => r.Id == reqEvectionMain.EmpId);
            empName = employee.Name;

            rptList.DataSource = reqEvectionMain.ReqEvectionSchedules;
            rptList.DataBind();
            rptVoyage.DataSource = reqEvectionMain.ReqEvectionVoyages;
            rptVoyage.DataBind();
            rptFlighter.DataSource = reqEvectionMain.ReqEvectionFlighters;
            rptFlighter.DataBind();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            ApolloOaDataContext ctx = new ApolloOaDataContext(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
            string formNo = Request.QueryString["formNo"];
            ReqEvectionMain reqEvectionMain = ctx.ReqEvectionMains.Single(r => r.FormNo == formNo);
            reqEvectionMain.RealCost = int.Parse(RealCost.Value);
            reqEvectionMain.RealStartTime = DateTime.Parse(RealStartTime.Value);
            reqEvectionMain.RealEndTime = DateTime.Parse(RealEndTime.Value);
            reqEvectionMain.Remarks = Remarks.Value;
            reqEvectionMain.StatusId = 5;
            ctx.SubmitChanges();
            Response.Write("<script>window.returnValue='Success';window.close();</script>");
        }
    }
}